<?php
	$TEMP->set_file(array('handle' => DIR_VIEW_DEAN . 'facultyAssignSubject.html'));
	$FID 	= _GET('fid');
	$CID 	= _GET('cid');
	$HASH 	= _GET('hash');
	
	if (!empty($FID)) {
		$faculty = $PI->getPersonalInformation($FID);
		$profName = $faculty['first_name'] . ' ' . $faculty['last_name'];
	}
	
	if (!empty($FID)) {
		$course 	= $DSC->getCourse($CID);
		$courseDesc = $course['course_desc'];
		$courseCode = $course['course_code'];
	}
	
	$profSubjectList = $DSC->getProfSubjectList($FID);
	if ( (!empty($profSubjectList)) ) {
		$TEMP->set_block('handle',  'subjects', 'subjectsRow');
		$bgcolor2 	= LOOPING_F0F;
		$numCount2 	= 1;
		foreach($profSubjectList as $profSubjectListValue) {
			$TEMP->set_var(array('subject_desc' => $profSubjectListValue['course_code']  . " : " . $profSubjectListValue['subj_desc'],
						 		 'numbering2' 	=> $numCount2));
								 
			$TEMP->parse('subjectsRow', 'subjects', true);
			$bgcolor2 = ($bgcolor2 == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$numCount2++;
			
		}
	}
	else {
		$TEMP->set_var(array('subject_desc' => 'No Record Found.',
						 	 'numbering2' 	=> ''));
	}
	
	$semesterLinker = $DSC->getSemesterLinker($CID);

	if ( (!empty($semesterLinker)) ) {
		$TEMP->set_block('handle',  'semester', 'semesterRow');
		$bgcolor 	= LOOPING_F0F;
		$numCount 	= 1;
		foreach($semesterLinker as $semesterLinkerField => $semesterLinkerValue) {
			
			$semDesc 	 = $semesterLinkerValue['sem_desc'];
			$semLinkerID = $semesterLinkerValue['sem_linker_idPK'];
			
			$subjectListingSemLinker = $DSC->getSubjectListingSemLinker($semLinkerID, $activeYear);

			if( !empty($subjectListingSemLinker) && $semesterLinkerValue['is_deleted'] == 'N' ) {
				$subjectListing = '<tr align="center" class="display-none" id="tr_subject_list' . $semLinkerID . '">
										<td class="transfery-td-bot"></td>
										<td class="transfery-td-bot" align="left">';
				foreach($subjectListingSemLinker as $subjectListingSemLinkerValue) {
					$subjID 		= $subjectListingSemLinkerValue['subj_idPK'];
					$subjDesc 		= $subjectListingSemLinkerValue['subj_desc'];
					
					$profSubj 	 = $DSC->getProfSubjectList($FID, $subjID);
					$notProfSubj = $DSC->getProfSubjectList($FID, $subjID, false);

					if (!empty($profSubj)) {
						$hiddenValue = '1';
						$imgCheck 	 = 'checkbox_check';
						$imgOnClick	 = ' onclick="studNewEnrollyValue(\'' . $subjID . '\', \'' . $FID . '\', \'' . $activeYear . '\')"';
						$profName	 = '';
					}
					else {
						if (!empty($notProfSubj)) {
							$hiddenValue = '1';
							$imgCheck 	 = 'checkbox_disable';
							$imgOnClick	 = '';
							$profName	 = ' - [' . substr($notProfSubj[0]['first_name'],0,1) . '. ' . $notProfSubj[0]['last_name'] . ']';
						}
						else {
							$hiddenValue = '0';
							$imgCheck 	 = 'checkbox_uncheck';
							$imgOnClick	 = ' onclick="studNewEnrollyValue(\'' . $subjID . '\', \'' . $FID . '\', \'' . $activeYear . '\')"';
							$profName	 = '';
						}
					}
					
					$subjectListing .= '<div class="hover-light-div"><input type="hidden" id="hidden_subj_id' . $subjID . '" value="' . $hiddenValue . '"/><img id="but_subj_id' . $subjID . '" src="./application/images/icon/' . $imgCheck . '.png" border="0" ' . $imgOnClick . '/> ' . $subjDesc . ' (' . $subjectListingSemLinkerValue['subj_code'] . ')' . $profName .'</div>';
				}
				$subjectListing .= '</td></tr>';
			}
			else {
				$subjectListing = '<tr align="center" class="display-none" id="tr_subject_list' . $semLinkerID . '">
										<td class="transfery-td-bot"></td>
										<td class="transfery-td-bot" align="left"><div class="hover-light-div"><img src="./application/images/icon/checkbox_remove.png" border="0" /> No Record Found.</div></td></tr>';
			}
			
			$TEMP->set_var(array('sem_desc' 			=> '<div class="subj-year-semester-value">' . $semDesc . '</div>',
								 'sem_linker_id' 		=> $semLinkerID,
								 'subj_list'			=> $subjectListing,
								 'numbering'			=> $numCount));
								 
			$TEMP->parse('semesterRow', 'semester', true);
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$numCount++;
		}
	}
	else {
		$TEMP->set_var(array('sem_desc' 			=> '',
							 'add_subject_button' 	=> '',
							 'sem_linker_id' 		=> '',
							 'subject_listing'		=> ''));
	}
	
	$TEMP->set_var(array('dean_sub_menu'	=> $pageLib->deanSubMenu(DIR_IMAGES),
						 'prof_name' 		=> $profName,
						 'course_desc'		=> $courseDesc,
						 'fid'				=> $FID,
						 'cid'				=> $CID,
						 'hash'				=> hashRandom($FID.$CID.$courseDesc.$profName),
						));
?>